

#include <iostream>
using namespace std;

int search(int* nums, int sz, int tar)
{
    int left = 0, right = sz - 1;

    while (left <= right)
    {
        int mid = left + ((right - left) >> 1);

        if (tar == nums[mid])
            return mid;

        if (nums[mid] >= nums[left])
        {
            if (tar >= nums[left] && tar <= nums[mid])
                right = mid;
            else
                left = ++mid;
        }
        else
        {
            if (tar <= nums[right] && tar >= nums[mid+1])
                left = ++mid;
            else
                right = mid;
        }
    }

    return -1;
}

void Test1(void)
{
    int a[] = { 4,5,6,7,0,1,2 };
    //int a[] = {5, 1, 3};
    int sz = sizeof(a) / sizeof(a[0]);
    int tar = 0;

    cout << search(a, sz, tar) << endl;
}

struct ListNode 
{
    int val;
    struct ListNode* next;
};

int getDecimalValue1(struct ListNode* head)
{
    int cnt = 0, ans = 0;

    struct ListNode* cur = head;
    while (cur)
    {
        ++cnt;
        cur = cur->next;
    }

    cur = head;
    for (int i = 0; cur; cur = cur->next)
    {
        ans += ((cur->val) << (cnt - 1 - i));
        ++i;
    }

    return ans;
}

int getDecimalValue2(struct ListNode* head)
{
    struct ListNode* cur = head;

    int ans = 0;
    while (cur)
    {
        ans = (ans << 1) + (cur->val);
        //ans = (ans<<1)|(cur->val);

        cur = cur->next;
    }

    return ans;
}

// shared_ptr
//shared_ptr<T>& operator=(const shared_ptr<T>& sp)
//{
//    // sp1 = sp2
//    if (_ptr != sp._ptr)
//    {
//        if (0 == --(*_pcount))
//        {
//            delete _ptr;
//            delete _pcount0;
//        }
//
//        *sp._pcount++;
//        _ptr = sp._ptr;
//        _pcount = sp._pcount;
//    }
//
//    return *this;
//}

int main()
{
    Test1();



	return 0;
}